<template>
	<view class="content">
		<view class="textarea-view">
			<textarea class="textarea shadow fadeIn-1s" v-model="profile" maxlength="100"
				placeholder="填写你的个人简介,你的兴趣爱好、生活方式..."></textarea>
		</view>
		<button class="button shadow fadeIn-1s" @tap="onSubmitTap">保存</button>
	</view>
</template>

<script>
	import {
		updateProfile
	} from "@/network/UserApi.js";
	export default {
		data() {
			return {
				profile: "",
			}
		},

		onLoad(options) {
			this.profile = options.profile;
		},

		methods: {
			/**
			 * 保存按钮点击事件
			 */
			onSubmitTap: function() {
				let that = this;
				if (this.profile.length === 0) {
					this.toast("请输入简介");
					return;
				}
				updateProfile(this.profile).then(data => {
					that.toast("保存成功");
					uni.navigateBack();
				}).catch(err => {
					uni.showModal({
						content: err,
						title: "保存失败"
					});
				});
			}
		}
	}
</script>

<style lang="scss">
	.textarea {
		padding: 20rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		margin: 20rpx;
		border-radius: 20px;
		background-color: white;
		width: auto;
	}

	.button {
		margin: 20rpx;
		margin-top: 20px;
	}
</style>
